import { request } from '@/common/utils/axios';
import { HintCode, ResponseCode } from '@/common/utils/enum.ts';
import { WarmMessage } from "@/components/Warm/Messages";

export class Common {
    private RequestApi = {
        // 获取验证码接口
        "SMS" : "/sms"
    }

    constructor() {

    }

    /**
     * 获取验证码
     * @param phone
     * @param callback
     */
    public async getCode(phone: string, callback?: Function) {
        try {
            const res: any = await request({
                url: this.RequestApi.SMS + '/' + phone,
                method: 'PUT'
            });
            if (ResponseCode.SUCCESS !== res.code) WarmMessage({ type: HintCode.ERROR, text: res.msg })
            else {
                WarmMessage({
                    type: HintCode.SUCCESS,
                    text: "已为您发送验证码,请注意查收"
                });
                callback && callback();
            }
        } catch (e) {
            console.error(e);
        }
    }
}